@extends('admin.common.admin_main')
@section('container')
<div class="uc-body">
    <div class="box-wide">
        <div class="box-thin bg-gray">
            <div class="form">
                <div class="form-head">
                    <div class="tit">修改密码</div>
                </div>
                <div class="form-body">
                    <div class="row">
                        <div class="label">登录账号：</div>
                        <div class="control-text">
                            <div class="static">
                                <div class="static"><b>{{$account_phone}}</b></div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="label">旧密码：</div>
                        <div class="control-text">
                            <div class="static">
                                <input id="old_pwd" class="form-control" type="password">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="label">新密码：</div>
                        <div class="control-text">
                            <div class="static">
                                <input id="new_pwd" class="form-control" type="password">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="label">确认新密码：</div>
                        <div class="control-text">
                            <div class="static">
                                <input id="confirm_pwd" class="form-control" type="password">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="label">&nbsp;</div>
                        <div class="control-text">
                            <a id="submit" class="btn btn-warning">确定</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('script')
<script>
    (function ($) {
        $(function () {
            //保存
            $("#submit").click(function () {
                var $o = $("#old_pwd");
                var old_pwd = $o.val();
                if (!old_pwd) {
                    return showErr($o, "请输入旧密码！");
                }
                var $n = $("#new_pwd");
                var new_pwd = $n.val();
                if (!isPassword(new_pwd)) {
                    return showErr($n, "请输入新密码，8-32位包含至少一个数字和一个英文字母的组合！");
                }
                var $c = $("#confirm_pwd");
                var confirm_pwd = $c.val();
                if (new_pwd !== confirm_pwd) {
                    return showErr($c, "新输入的两次密码不一致！");
                }
                var $btn = $(this);
                $.ajax({
                    url: "/user/action",
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    data: {
                        old_pwd: old_pwd,
                        new_pwd: new_pwd,
                        action: 'update_user_pwd'
                    },
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        var result = data["result"];
                        var msg = data["msg"];
                        if (result === 0) {
                            $.Alert({
                                obj: $btn, txt: '密码修改成功，请重新登录！', callback: function () {
                                    $("#j_alert").remove();
                                    window.location.href = '/logout';
                                }
                            });
                        } else {
                            return showErr($btn, msg);
                        }
                    },
                    error: function (data) {
                        return showErr($btn, "修改失败！");
                    }
                });
            });
        });
    })(jQuery);
</script>
@endsection
